﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace GameEngine.Controller
{
    using PureMVC.Patterns;
    using PureMVC.Interfaces;
    using GameEngine.Model;
    using GameEngine.View.Components;

    public class TickCommand<ItemVOId> : SimpleCommand
        where ItemVOId : IComparable<ItemVOId>
    {
        static int ticks = 0;
        static DateTime previousTime = DateTime.Now;
        static EngineDataProxy<ItemVOId> engine;

        override public void Execute(INotification notification)
        {
            //TODO meter o engine a ouvir a notificacao?
           if(engine==null)
               engine = Facade.RetrieveProxy(EngineDataProxy <ItemVOId>.MYNAME) as EngineDataProxy<ItemVOId>;
           if (engine != null)
            engine.Tick();
            
            DateTime now = DateTime.Now;
            if (now.Second != previousTime.Second)
            {
                SendNotification(ApplicationFacade.FPS_NOTIFICATION, ticks);
                ticks = 0;
                previousTime = now;
            }
            else
                ticks++;
        }
    }
}
